package com.factorit.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.factorit.forms.LoginForm;
import com.factorit.mvc.MvcSession;
import com.factorit.security.SessionPrincipal;

/**
 * Action para el logueo en la aplicacion
 * 
 * @author gderosa
 * 
 */
public class LoginAction extends BaseDispatchableAction {

	public ActionForward login(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return mapping.findForward("login");
	}

	public ActionForward dashboard(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		LoginForm loginForm = (LoginForm) form;

		MvcSession session = getMvcSession(request.getSession());

		SessionPrincipal sessionPrincipal = getUserPrincipal(request);
		
		// session.getImages();
		populateRequest(request);
		return mapping.findForward("success");
	}

	public ActionForward logout(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		request.getSession().invalidate();
		return mapping.findForward("logout");
	}
}
